package cn.edu.njust;


import cn.edu.njust.limiter.CounterRateLimiter;
import cn.edu.njust.limiter.LeakBucketRateLimiter;
import cn.edu.njust.limiter.RateLimiter;
import cn.edu.njust.limiter.TokenBucketRateLimiter;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class Main {
    private Logger logger = LoggerFactory.getLogger(Main.class);

    private RateLimiter limiter;

    private int QPS = 100;

    private int FUEL_INTERVAL = 10;

    private int BUCKET_SIZE = 100;

    private int REQUESTS = 2000;

    @After
    public void runTest() throws InterruptedException {
        for (int i = 1; i <= REQUESTS; i++) {
            limiter.aquire();
            logger.info(i + "");
        }
    }

    @Test
    public void testCounterRateLimiter() {
        limiter = new CounterRateLimiter(QPS);
    }

    @Test
    public void testLeakBucketRateLimiter() {
        limiter = new LeakBucketRateLimiter(FUEL_INTERVAL);
    }

    @Test
    public void testTokenBucketRateLimiter() {
        limiter = new TokenBucketRateLimiter(BUCKET_SIZE, FUEL_INTERVAL);
    }
}
